home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / ip / ka9q / aztecnos.arc / 8530.ASM < prev    next >
Encoding:
Assembly Source File  |  1989-02-21  |  2.1 KB  |  112 lines

  1.     include lmacros.h
  2.  
  3.     procdef    write_scc,<<ctl,word>,<reg,byte>,<val,byte>>
  4.     pushf    
  5.     mov    dx,ctl
  6.     mov    al,reg
  7.     cmp    al,0
  8.     jz    wr0        ; no need to set register 0
  9.     cli
  10.     out    dx,al
  11. ; allow enough delay for 10 MHz 80286 and a 3.6 MHz 8530
  12. ; each nop is 3 clock ticks (300 ns @ 10 MHz).
  13. ; The 8530 requires a delay of 6 PCLK cycles (1.666 uS at 3.6 MHz)
  14.     nop
  15.     nop
  16.     nop
  17.     nop
  18.     nop
  19.     nop
  20. wr0:    mov    al,val
  21.     out    dx,al
  22.     popf
  23.     pret
  24.     pend    write_scc
  25.  
  26.     procdef    read_scc,<<ctl1,word>,<reg1,byte>>
  27.     pushf
  28.     mov    dx,ctl1
  29.     mov    al,reg1
  30.     cmp    al,0
  31.     jz    rd0    ; no need to set reg if R0
  32.     cli
  33.     out    dx,al
  34. ; allow enough delay for 10 MHz 80286 and a 3.6 MHz 8530
  35.     nop
  36.     nop
  37.     nop
  38.     nop
  39.     nop
  40.     nop
  41. rd0:    in    al,dx
  42.     mov    ah,0
  43.     popf
  44.     pret
  45.     pend    read_scc
  46.  
  47. ; Read packets from the 8530 receiver.
  48. ; Returns when either a good frame is received, or when carrier drops.
  49. ; If a good frame is received, the length is returned; otherwise -1.
  50.     procdef    rx8530,<<control,word>,<data,word>,<buf,ptr>,<bufsize,word>>
  51.  
  52.     cld
  53.     push    di
  54.  
  55. restart:mov    cx,0        ; cnt = 0
  56.     mov    di,buf        ; cp = buf
  57.  
  58. rxloop:    mov    dx,control    ; read status
  59.     in    al,dx        ; into al
  60.     test    al,08h        ; DCD still present?
  61.     jz    dcdoff        ; nope, quit
  62.     test    al,080h        ; Abort?
  63.     jnz    restart        ; yes, start again
  64.     test    al,01h        ; character available?
  65.     jz    nochar        ; nope, go on
  66.     mov    dx,data
  67.     in    al,dx        ; get it
  68.     stosb            ; and stash: *cp++ = char
  69.     inc    cx        ; cnt++
  70.     cmp    cx,bufsize    ; cx == bufsize?
  71.     jnz    rxloop
  72.  
  73.     mov    dx,control    ; buffer overflowed; abort receiver
  74.     mov    al,3        ; select register 3
  75.     out    dx,al
  76.     mov    al,0d9h        ; ENT_HM|RxENABLE|RxCRC_ENAB|Rx8
  77.     nop
  78.     nop
  79.     nop
  80.     nop
  81.     nop
  82.     out    dx,al
  83.     jmp    restart
  84.  
  85. nochar:    mov    al,1        ; Select error register (R1)
  86.     mov    dx,control
  87.     out    dx,al
  88.     nop
  89.     nop
  90.     nop
  91.     nop
  92.     nop
  93.     nop
  94.     in    al,dx        ; read error reg (R1)
  95.     test    al,080h        ; end of frame?
  96.     jz    rxloop        ; nope, keep looking
  97.  
  98.     test    al,040h        ; End of frame. CRC error?
  99.     jnz    restart        ; yup; start again
  100.     mov    ax,cx        ; good frame; return with count
  101.     pop    di
  102.     pret
  103.  
  104. dcdoff:
  105.     mov    ax,0ffffh    ; DCD dropped, return -1
  106.     pop    di
  107.     pret
  108.  
  109.     pend    rx8530
  110.     end
  111.  
  112.